#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<stack>
#include<cmath>
#include<string>
#include<unordered_set>
#include<map>
using namespace std;


void solve()
{
    int n, k; cin >> n >> k;
    vector<long long> arr;
    for (int i = 0; i < n; i++)
    {
        long long temp; cin >> temp;
        arr.push_back(temp);
    }
    map<long long, int> ma;
    for (int i = 0; i < arr.size(); i++)
    {
        ma[arr[i]] += 1;
    }
    vector<long long> temp;
    for (auto& x : ma)
    {
        if (x.second > 1) ma[x.first + k] += x.second - 1;
        temp.push_back(x.first);
    }
    if (temp.front() != 0)
    {
        cout << 0 << endl; return;
    }
    for (int i = 0; i < temp.size() - 1; i++)
    {
        if (temp[i + 1] - temp[i] > 1)
        {
            cout << temp[i] + 1 << endl; return;
        }
    }
    cout << temp.back() + 1 << endl;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}